package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.dao.WmsReservoirUtilizationMapper;
import com.jy.wms.dao.WmsproductWarningMapper;
import com.jy.wms.pojo.WmsproductWarning;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WmsproductWarningService extends BaseService<WmsproductWarningMapper,WmsproductWarning> {
    @Resource
    private WmsReservoirUtilizationMapper wmsReservoirUtilizationMapper;

    /**
     * 分页查询
     * @param entity 实体
     * */
    @BaseServiceDescribe(moduleName = "产品预警分析报表", btnName = "分页查询")
    public Page<WmsproductWarning> baseHarvestPage(WmsproductWarning entity) throws Exception {
        Page<WmsproductWarning> list = null;
        try {
            PageHelper.startPage(entity.getPage(), entity.getRows());
            list=(Page<WmsproductWarning>) dao.baseSelectPage(entity);//分页查询
            for(WmsproductWarning wmsproductWarning:list){
                WmsproductWarning wmsproductWarning1=dao.selectProducrt(wmsproductWarning.getCpbm());
                if(wmsproductWarning1!=null){
                    wmsproductWarning.setJsyxl(wmsproductWarning1.getJsyxl());
                }else{
                    wmsproductWarning.setJsyxl(0);
                }
                if(wmsproductWarning.getJskc()>wmsproductWarning.getJsyxl()){
                    wmsproductWarning.setKcbhyj("库存正常");
                    System.out.println(wmsproductWarning.getKcbhyj());
                }else{
                    wmsproductWarning.setKcbhyj("库存不足");
                }
            }
            return list;
        } catch (Exception e) {
            throw new ServiceException("产品预警分析报表分页查询失败", e);
        }
    }

    /**
     * 导出产品预警分析信息
     *
     * @param entity
     * @return
     */
    @BaseServiceDescribe(moduleName = "导出报表",btnName = "产品预警分析报表")
    public List<WmsproductWarning> exportWmsproductWarning(WmsproductWarning entity){
        List<WmsproductWarning> list=dao.exportWmsproductWarning(entity);
        for(WmsproductWarning wmsproductWarning:list){
            WmsproductWarning wmsproductWarning1=dao.selectProducrt(wmsproductWarning.getCpbm());
            if(wmsproductWarning1!=null){
                wmsproductWarning.setJsyxl(wmsproductWarning1.getJsyxl());
            }else{
                wmsproductWarning.setJsyxl(0);
            }
            if(wmsproductWarning.getJskc()>wmsproductWarning.getJsyxl()){
                wmsproductWarning.setKcbhyj("库存正常");
                System.out.println(wmsproductWarning.getKcbhyj());
            }else{
                wmsproductWarning.setKcbhyj("库存不足");
            }
        }
        return list;
    }
}
